package com.qpcy.controller;

import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.qpcy.utils.ResponseResult;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import com.qpcy.entity.HotProduct;
import com.qpcy.service.HotProductService;
import org.springframework.web.bind.annotation.RestController;
import java.io.Serializable;
import java.util.List;
import static com.qpcy.entity.table.HotProductTableDef.HOT_PRODUCT;


/**
 *  控制层。
 *
 * @author DELL
 * @since 2024-10-27
 */
@RestController
@RequestMapping("/hotProduct")
public class HotProductController {

    @Autowired
    private HotProductService hotProductService;

    /**
     * 获取爆款产品
     *
     * @return
     */
    @GetMapping("/getAll")
    public ResponseResult getAll() {
        QueryWrapper.create()
                .orderBy(HOT_PRODUCT.SORT.asc());
        return hotProductService.getAll();
    }

    /**
     * 保存爆款产品
     *
     * @param hotProduct
     * @return
     */
    @PostMapping("/save")
    public ResponseResult getAll(@RequestBody HotProduct hotProduct) {
        return ResponseResult.success(hotProductService.save(hotProduct));
    }

    /**
     * 更新爆款产品
     *
     * @param hotProduct
     * @return
     */
    @PostMapping("/update")
    public ResponseResult update(@RequestBody HotProduct hotProduct) {
        return ResponseResult.success(hotProductService.updateById(hotProduct));
    }

    /**
     * 删除爆款产品
     *
     * @param id
     * @return
     */
    @PostMapping("/delete")
    public ResponseResult delete(int id) {
        return ResponseResult.success(hotProductService.removeById(id));
    }

}
